/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.weeho.dongyong.utils;

import java.util.Collections;
import java.util.List;

/**
 *
 * @author yincl
 */
public class MathUtils {

    public static int TryParseInt(String text, int defaultInt) {
        try {
            return Integer.parseInt(text);
        } catch (Exception ex) {
            return defaultInt;
        }
    }

    /**
     * 获取list中的最大值
     * @param list
     * @return
     */
    public static Long getMaxDouble(List list){
        double max = (Long)Collections.max(list);
       // double min = (Long) Collections.min(list);
        return (long) max;
    }

    /**
     * 获取list中的最小值（Long型）
     * @param list
     * @return
     */
    public static Long getMinDouble(List list){

       // double max = (Long)Collections.max(list);
        double min = (Long)Collections.min(list);
        return (long) min;
    }

    /**
     * 获取某个数的相反数
     * @param n
     * @return
     */
    public static int getInverse(int n){
        return ~n+1;
    }

    /**
     * 判断两数相加是否溢出
     * @param a
     * @param b
     * @return
     */
    public static boolean isOverflow(int a,int b){
        if(a > 0 && b > 0 && a > Integer.MAX_VALUE - b) return true;
        if(a < 0 && b < 0 && a < Integer.MIN_VALUE - b) return true;
        return false;
    }

}
